package com.hzhr.iot.core.util;

import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

public class HzhrTypeUtil {
    //region str2
    public static String string2string(String str) {
        return str;
    }
    public static List<String> stringList2stringList(List<String> sl) {
        if (sl == null) return null;
        List<String> result = new ArrayList<>();
        for (String s:sl) {
            result.add(string2string(s));
        }
        return result;
    }
    public static Byte string2byte(String str) {
        if (StringUtils.isEmpty(str)) return null;
        return Byte.parseByte(str);
    }
    public static List<Byte> stringList2byteList(List<String> sl) {
        if (sl == null) return null;
        List<Byte> result = new ArrayList<>();
        for (String s:sl) {
            result.add(string2byte(s));
        }
        return result;
    }
    public static Short string2short(String str) {
        if (StringUtils.isEmpty(str)) return null;
        return Short.parseShort(str);
    }
    public static List<Short> stringList2shortList(List<String> sl) {
        if (sl == null) return null;
        List<Short> result = new ArrayList<>();
        for (String s:sl) {
            result.add(string2short(s));
        }
        return result;
    }
    public static Integer string2integer(String str) {
        if (StringUtils.isEmpty(str)) return null;
        return Integer.parseInt(str);
    }
    public static List<Integer> stringList2integerList(List<String> sl) {
        if (sl == null) return null;
        List<Integer> result = new ArrayList<>();
        for (String s:sl) {
            result.add(string2integer(s));
        }
        return result;
    }
    public static Float string2float(String str) {
        if (StringUtils.isEmpty(str)) return null;
        return Float.parseFloat(str);
    }
    public static List<Float> stringList2floatList(List<String> sl) {
        if (sl == null) return null;
        List<Float> result = new ArrayList<>();
        for (String s:sl) {
            result.add(string2float(s));
        }
        return result;
    }
    public static Double string2double(String str) {
        if (StringUtils.isEmpty(str)) return null;
        return Double.parseDouble(str);
    }
    public static List<Double> stringList2doubleList(List<String> sl) {
        if (sl == null) return null;
        List<Double> result = new ArrayList<>();
        for (String s:sl) {
            result.add(string2double(s));
        }
        return result;
    }
    public static Long string2long(String str) {
        if (StringUtils.isEmpty(str)) return null;
        return Long.parseLong(str);
    }
    public static List<Long> stringList2longList(List<String> sl) {
        if (sl == null) return null;
        List<Long> result = new ArrayList<>();
        for (String s:sl) {
            result.add(string2long(s));
        }
        return result;
    }
    public static Boolean string2boolean(String str) {
        if (StringUtils.isEmpty(str)) return null;
        return Boolean.parseBoolean(str);
    }
    public static List<Boolean> stringList2booleanList(List<String> sl) {
        if (sl == null) return null;
        List<Boolean> result = new ArrayList<>();
        for (String s:sl) {
            result.add(string2boolean(s));
        }
        return result;
    }
    public static BigDecimal string2bigdecimal(String str) {
        if (StringUtils.isEmpty(str)) return null;
        return new BigDecimal(str);
    }
    public static List<BigDecimal> stringList2bigdecimalList(List<String> sl) {
        if (sl == null) return null;
        List<BigDecimal> result = new ArrayList<>();
        for (String s:sl) {
            result.add(string2bigdecimal(s));
        }
        return result;
    }
    public static Date string2date(String str) {
        if (StringUtils.isEmpty(str)) return null;
        return new Date(Long.parseLong(str));
    }
    public static List<Date> stringList2dateList(List<String> sl) {
        if (sl == null) return null;
        List<Date> result = new ArrayList<>();
        for (String s:sl) {
            result.add(string2date(s));
        }
        return result;
    }
    //endregion

    //region obj2
    public static Object object2object(Object o) {
        return o;
    }
    public static List<Object> objectList2objectList(List<Object> ol) {
        if (ol == null) return null;
        List<Object> result = new ArrayList<>();
        for (Object o:ol) {
            result.add(object2object(o));
        }
        return result;
    }
    public static String object2string(Object o) {
        if (o == null) return null;
        return o.toString();
    }
    public static List<String> objectList2stringList(List<Object> ol) {
        if (ol == null) return null;
        List<String> result = new ArrayList<>();
        for (Object o:ol) {
            result.add(object2string(o));
        }
        return result;
    }
    public static Integer object2integer(Object o) {
        if (o == null) return null;
        return Integer.parseInt(o.toString());
    }
    public static List<Integer> objectList2integerList(List<Object> ol) {
        if (ol == null) return null;
        List<Integer> result = new ArrayList<>();
        for (Object o:ol) {
            result.add(object2integer(o));
        }
        return result;
    }
    public static Float object2float(Object o) {
        if (o == null) return null;
        return Float.parseFloat(o.toString());
    }
    public static List<Float> objectList2floatList(List<Object> ol) {
        if (ol == null) return null;
        List<Float> result = new ArrayList<>();
        for (Object o:ol) {
            result.add(object2float(o));
        }
        return result;
    }
    public static Double object2double(Object o) {
        if (o == null) return null;
        return Double.parseDouble(o.toString());
    }
    public static List<Double> objectList2doubleList(List<Object> ol) {
        if (ol == null) return null;
        List<Double> result = new ArrayList<>();
        for (Object o:ol) {
            result.add(object2double(o));
        }
        return result;
    }
    public static Long object2long(Object o) {
        if (o == null) return null;
        return Long.parseLong(o.toString());
    }
    public static List<Long> objectList2longList(List<Object> ol) {
        if (ol == null) return null;
        List<Long> result = new ArrayList<>();
        for (Object o:ol) {
            result.add(object2long(o));
        }
        return result;
    }
    public static BigDecimal object2bigdecimal(Object o) {
        if (o == null) return null;
        return new BigDecimal(o.toString());
    }
    public static List<BigDecimal> objectList2bigdecimalList(List<Object> ol) {
        if (ol == null) return null;
        List<BigDecimal> result = new ArrayList<>();
        for (Object o:ol) {
            result.add(object2bigdecimal(o));
        }
        return result;
    }
    public static Boolean object2boolean(Object o) {
        if (o == null) return null;
        return Boolean.parseBoolean(o.toString());
    }
    public static List<Boolean> objectList2booleanList(List<Object> ol) {
        if (ol == null) return null;
        List<Boolean> result = new ArrayList<>();
        for (Object o:ol) {
            result.add(object2boolean(o));
        }
        return result;
    }
    public static Date object2date(Object o) {
        if (o == null) return null;
        return new Date(Long.parseLong(o.toString()));
    }
    public static List<Date> objectList2dateList(List<Object> ol) {
        if (ol == null) return null;
        List<Date> result = new ArrayList<>();
        for (Object o:ol) {
            result.add(object2date(o));
        }
        return result;
    }
    public static List object2list(Object o) {
        if (o == null) return null;
        if (o instanceof String) {
            List result = Arrays.asList(o.toString().split(","));
            return result;
        }
        return (List) o;
    }
    //endregion

    //region short2
    public static Short short2short(Short s) {
        return s;
    }
    public static List<Short> shortList2shortList(List<Short> sl) {
        if (sl == null) return null;
        List<Short> result = new ArrayList<>();
        for (Short o:sl) {
            result.add(short2short(o));
        }
        return result;
    }
    public static String short2string(Short s) {
        if (s == null) return null;
        return s.toString();
    }
    public static List<String> shortList2stringList(List<Short> sl) {
        if (sl == null) return null;
        List<String> result = new ArrayList<>();
        for (Short o:sl) {
            result.add(short2string(o));
        }
        return result;
    }
    //endregion

    //region integer2
    public static Integer integer2integer(Integer i) {
        return i;
    }
    public static List<Integer> integerList2integerList(List<Integer> il) {
        if (il == null) return null;
        List<Integer> result = new ArrayList<>();
        for (Integer o:il) {
            result.add(integer2integer(o));
        }
        return result;
    }
    public static String integer2string(Integer i) {
        if (i == null) return null;
        return i.toString();
    }
    public static List<String> integerList2stringList(List<Integer> il) {
        if (il == null) return null;
        List<String> result = new ArrayList<>();
        for (Integer o:il) {
            result.add(integer2string(o));
        }
        return result;
    }
    //endregion

    //region float2
    public static Float float2float(Float f) {
        return f;
    }
    public static List<Float> floatList2floatList(List<Float> fl) {
        if (fl == null) return null;
        List<Float> result = new ArrayList<>();
        for (Float o:fl) {
            result.add(float2float(o));
        }
        return result;
    }
    public static String float2string(Float f) {
        if (f == null) return null;
        return f.toString();
    }
    public static List<String> floatList2stringList(List<Float> fl) {
        if (fl == null) return null;
        List<String> result = new ArrayList<>();
        for (Float o:fl) {
            result.add(float2string(o));
        }
        return result;
    }
    //endregion

    //region double2
    public static Double double2double(Double d) {
        return d;
    }
    public static List<Double> doubleList2doubleList(List<Double> dl) {
        if (dl == null) return null;
        List<Double> result = new ArrayList<>();
        for (Double o:dl) {
            result.add(double2double(o));
        }
        return result;
    }
    public static String double2string(Double d) {
        if (d == null) return null;
        return d.toString();
    }
    public static List<String> doubleList2stringList(List<Double> dl) {
        if (dl == null) return null;
        List<String> result = new ArrayList<>();
        for (Double o:dl) {
            result.add(double2string(o));
        }
        return result;
    }
    //endregion

    //region long2
    public static Long long2long(Long l) {
        return l;
    }
    public static List<Long> longList2longList(List<Long> ll) {
        if (ll == null) return null;
        List<Long> result = new ArrayList<>();
        for (Long o:ll) {
            result.add(long2long(o));
        }
        return result;
    }
    public static String long2string(Long l) {
        if (l == null) return null;
        return l.toString();
    }
    public static List<String> longList2stringList(List<Long> ll) {
        if (ll == null) return null;
        List<String> result = new ArrayList<>();
        for (Long o:ll) {
            result.add(long2string(o));
        }
        return result;
    }
    public static Date long2date(Long l) {
        if (l == null) return null;
        return new Date(l);
    }
    public static List<Date> longList2dateList(List<Long> ll) {
        if (ll == null) return null;
        List<Date> result = new ArrayList<>();
        for (Long o:ll) {
            result.add(long2date(o));
        }
        return result;
    }
    //endregion

    //region boolean2
    public static Boolean boolean2boolean(Boolean b) {
        return b;
    }
    public static List<Boolean> booleanList2booleanList(List<Boolean> bl) {
        if (bl == null) return null;
        List<Boolean> result = new ArrayList<>();
        for (Boolean o:bl) {
            result.add(boolean2boolean(o));
        }
        return result;
    }
    public static String boolean2string(Boolean b) {
        if (b == null) return null;
        return b.toString();
    }
    public static List<String> booleanList2stringList(List<Boolean> bl) {
        if (bl == null) return null;
        List<String> result = new ArrayList<>();
        for (Boolean o:bl) {
            result.add(boolean2string(o));
        }
        return result;
    }
    //endregion

    //region date2
    public static Date date2date(Date d) {
        return d;
    }
    public static List<Date> dateList2dateList(List<Date> dl) {
        if (dl == null) return null;
        List<Date> result = new ArrayList<>();
        for (Date d:dl) {
            result.add(date2date(d));
        }
        return result;
    }
    public static String date2string(Date d) {
        if (d == null) return null;
        return d.getTime() + "";
    }
    public static List<String> dateList2stringList(List<Date> dl) {
        if (dl == null) return null;
        List<String> result = new ArrayList<>();
        for (Date d:dl) {
            result.add(date2string(d));
        }
        return result;
    }
    public static Long date2long(Date d) {
        if (d == null) return null;
        return d.getTime();
    }
    public static List<Long> dateList2longList(List<Date> dl) {
        if (dl == null) return null;
        List<Long> result = new ArrayList<>();
        for (Date d:dl) {
            result.add(date2long(d));
        }
        return result;
    }
    //endregion

}
